/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xos_http.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __MSG_NOTIFY_MSG_NOTIFY_TCP_H__
#define __MSG_NOTIFY_MSG_NOTIFY_TCP_H__

namespace xos_http
{
    class connection;
    class port;

    class notify_tcp
    {
    public:
        notify_tcp();
        ~notify_tcp();

    public:
        int post_init_server( xos_box::i_msg *& pMsg, connection* pConnect );
        int post_connect( xos_box::i_msg *& pMsg, connection* pConnect );
        int post_send( xos_box::i_msg *& pMsg, connection* pConnect, const char* lpszData, bool bCloseAfterSend, bool bQuitAfterSend );
        int post_send( xos_box::i_msg *& pMsg, connection* pConnect, const char * lpszData, int nLen, bool bCloseAfterSend, bool bQuitAfterSend );
        int post_send( xos_box::i_msg *& pMsg, connection* pConnect, xos_box::i_buf*& pBuf, bool bCloseAfterSend, bool bQuitAfterSend );
        int post_send( connection * pConnect, xos_box::i_list * pList, bool bCloseAfterSend, bool bQuitAfterSend );
        int post_shutdown( xos_box::i_msg *& pMsg, connection* pConnect, int how );
        int helper_post_close( xos_box::i_msg *& pMsg, connection * pConnect, int onoff, int linger );
        int post_close( xos_box::i_msg *& pMsg, connection* pConnect );
        int post_reset( xos_box::i_msg *& pMsg, connection* pConnect );

    protected:
        int on_init_server( xos_box::i_msg *& pMsg );
        int on_accept( xos_box::i_msg *& pMsg );
        int on_connect( xos_box::i_msg*& pMsg );
        int on_send( xos_box::i_msg*& pMsg );
        int on_recv( xos_box::i_msg*& pMsg );
        int on_shutdown( xos_box::i_msg*& pMsg );
        int on_close( xos_box::i_msg*& pMsg );

    protected:
        int test_tcp_connect( xos_box::i_msg *& pMsg, connection * pServerConnect );
        int test_ssl_recv( xos_box::i_msg *& pMsg, connection * pConnect, xos_box::i_buf *& pBuf );
        int test_ssl_connect( xos_box::i_msg *& pMsg, connection * pConnect );

    public:
        int proc( xos_box::i_msg *& pMsg );

    };

} // xos_http

#endif // __MSG_NOTIFY_MSG_NOTIFY_TCP_H__
